package com.dries.security.core.social.wechat.connect;

import com.dries.security.core.social.wechat.api.WeChat;
import com.dries.security.core.social.wechat.api.WeChatUserInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.social.connect.ApiAdapter;
import org.springframework.social.connect.ConnectionValues;
import org.springframework.social.connect.UserProfile;

/**
 * @Description:
 * @Author ZSY
 * @createTime 2020/9/17 11:12
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class WeChatAdapter implements ApiAdapter<WeChat> {

    private String openId;

    @Override
    public boolean test(WeChat weChat) {
        return true;
    }

    @Override
    public void setConnectionValues(WeChat weChat, ConnectionValues connectionValues) {

        WeChatUserInfo profile = weChat.getUserInfo(openId);
        connectionValues.setProviderUserId(profile.getOpenid());
        connectionValues.setDisplayName(profile.getNickname());
        connectionValues.setImageUrl(profile.getHeadimgurl());

    }

    @Override
    public UserProfile fetchUserProfile(WeChat weChat) {
        return null;
    }

    @Override
    public void updateStatus(WeChat weChat, String s) {
        //do nothing
    }
}
